import request from "@/utils/request";
import { type AxiosPromise } from "axios";
import type { LoginData, UserInfo, MyResponseType, basicInfo, educationInfo, forJobInfo } from "@/api/user/types";

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<MyResponseType> {
  /* const { msg, data,code } = response.data; 限制的是response里的data类型 */
  const formData = new FormData();
  formData.append("phone", data.phone);
  formData.append("password", data.password);
  formData.append("signType", data.signType || "");
  return request({
    url: "/api/user/login",
    method: "post",
    data: formData
  });
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/api/user/logout",
    method: "delete",
  });
}

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfoApi(): AxiosPromise {
  return request({
    url: "/api/userInfo/getUserInfo",
    method: "get"
  });
}

/* 修改用户基本信息 */
export function updateBasicInfo(data: basicInfo) {
  return request({
    url: "/api/userInfo/updateBasicInfo",
    method: "post",
    data
  })
}

/* 上传简历pdf,图片 */
export function postResumeFileApi(file:File){
  const formData = new FormData();
  formData.append("resume", file);
  return request({
    url:'/api/api/searchImage',
    method:'post',
    data:formData,
    headers:{
      'Content-Type' : 'multipart/form-data'
    }
  })
}

/* 修改用户个人教育信息 */
export function updateEducationInfo(data: educationInfo) {
  return request({
    url: "/api/userInfo/updateEducationInfo",
    method: 'post',
    data
  })
}

/* 修改用户个人期望职位信息 */
export function updateForjobInfo(data: forJobInfo) {
  return request({
    url: "/api/userInfo/updateForjobInfo",
    method: 'post',
    data
  })
}

/* 修改修改用户个人头像 */
export function updateUserProfile(data: File) {
  const form = new FormData();
  form.append("profile", data)
  const url = "/api/userInfo/updateUserProfile"
  return request({
    url,
    method:"post",
    data:form,
    headers:{
      'Content-Type':'multipart/form-data'
    }
  })
}

/* 增加求职者工作或者实习经历 */
export function addWorkExperience(data: any) {
  return request({
    url: "/api/userInfo/addJobExperience",
    method: "post",
    data
  })
}

/* 根据ID删除求职者工作或实习经历 */
export function deleteWorkExperience(id: string) {
  const form =new FormData();
  form.append("id",id)
  return request({
    url: `/api/userInfo/delJobExById`,
    method: "post",
    data:form,
    headers:{
      // Long id
      //我真的服了，你后端要求请求这么大一个整数long干嘛啊！！！
      'Content-Type':'multipart/form-data'
    }
  })
}

/* 根据修改求职者工作或实习经历 */
export function updateWorkExperience(data: any) {
  return request({
    url: "/api/userInfo/updJobExById",
    method: "post",
    data
  })
}

/* 根据ID增加项目经历 */
export function addProjectExperience(data: any) {
  return request({
    url: "/api/userInfo/addProjectEx",
    method: "post",
    data
  })
}

/* 根据ID删除项目经历 */
export function deleteProjectExperience(id: string) {
  const form =new FormData();
  form.append("id", id)
  return request({
    url: `/api/userInfo/delProjectExById`,
    method: "post",
    data:form,
    headers:{
      // Long id
      //我真的服了，你后端要求请求这么大一个整数long干嘛啊！！！
      'Content-Type':'multipart/form-data'
    }
  })
}

/* 根据更新项目经历 */
export function updateProjectExperience(data: any) {
  return request({
    url: "/api/userInfo/updProjectExById",
    method: "post",
    data
  })
}

/* 建立webSocket连接 */
export function createWebSocket() {
  return new WebSocket("ws://localhost:8080/websocket");
}

export function getRecommodJob(){
  return request({
    url:'/api/company/geek/RecommodJob',
    method:"get"
  })
}